﻿using Direct.IDAL.ServiceCenterApply;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.User;
using DirectSell.Model.ServiceCenter;
using Direct.IDAL.User.Jurisdiction;
using System.Collections;

namespace DirectSell.BLL.User.ServiceCenterApply
{
    /// <summary>
    /// 服务中心业务层
    /// </summary>
    public class ServiceCenterService :UserService
    {

        #region 初始化数据
        /// <summary>
        /// 日志记录
        /// </summary>
        protected override string LogFile => "服务中心申请";
        /// <summary>
        /// 服务中心仓储接口
        /// </summary>
        protected IServiceCenterRepository _serviceCenter { get; set; }

        public ServiceCenterService(IServiceCenterRepository serviceCenter)
        {
            this._serviceCenter = serviceCenter;
        }
        #endregion

        #region 服务中心申请操作
        /// <summary>
        /// 服务中心申请操作
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected override UserRespCode Operation<T>(T param)
        {
            var model = param as ServiceCenter;

            if (model == null)
            {
                return UserRespCode.传入参数不正确;
            }

            if (!_serviceCenter.RepeatLock(model))
            {
                return UserRespCode.重复提交;
            }

            Log(model);

            Hashtable hsTable = new Hashtable();

            _serviceCenter.Apply(model,ref hsTable);
            
            _serviceCenter.ModifyUser(model, ref hsTable);

            if (!_serviceCenter.CommitDapperTranLock(hsTable))
            {
                return UserRespCode.失败;
            }
            return UserRespCode.成功;
        }
        #endregion

    }
}
